//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	SecuritySecurableAssignments.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Collections.Generic;

namespace Smart.Common.Security
{
	/// <summary>
	/// Security securable assignments
	/// </summary>
	public class SecuritySecurableAssignments
	{
		/// <summary>
		/// Securable object type
		/// </summary>
		public SecurableType SecurableType { get; set; }

		/// <summary>
		/// Securable object to secure
		/// </summary>
		public ISecurable Securable { get; set; }

		/// <summary>
		/// Security policy
		/// </summary>
		public SecurityPolicy Policy { get; set; }

		/// <summary>
		/// Inherit existing assignments (left existing assignments)
		/// </summary>
		public bool Inherit { get; set; }

		/// <summary>
		/// Set security assignments to current scope only
		/// </summary>
		public bool CurrentScopeOnly { get; set; }

		/// <summary>
		/// Security assignments
		/// </summary>
		public List<SecurityAssignment> Assignments { get; set; }

		/// <summary>
		/// Security securable assignments
		/// </summary>
		public SecuritySecurableAssignments(SecurableType securableType, ISecurable securable, SecurityPolicy policy, bool inherit, bool currentScopeOnly)
		{
			SecurableType = securableType;
			Securable = securable;
			Policy = policy;
			Inherit = inherit;
			CurrentScopeOnly = currentScopeOnly;

			Assignments = new List<SecurityAssignment>();
		}

		/// <summary>
		/// Add security assignment
		/// </summary>
		public virtual void Add(string principal, string accessLevel)
		{
			Assignments.Add(new SecurityAssignment { Principal = principal, AccessLevel = accessLevel });
		}
	}
}